﻿using System;

namespace RuTracker.Interface.Login
{
    public class LoginResults
    {
        private LoginResults(string html, string catchaUrl, string captureCode, string captureSid, bool succeeded)
        {
            CaptchaUrl = catchaUrl;
            CaptchaSid = captureSid;
            CaptchaCode = captureCode;
            Html = html;
            Succeeded = succeeded;
        }

        public static LoginResults CreateCatchaRequired(string html, string catchaUrl, string captchaCode, string captchaSid)
        {
            if (string.IsNullOrEmpty(catchaUrl))
                throw new ArgumentNullException("catchaUrl");

            if (string.IsNullOrEmpty(captchaCode))
                throw new ArgumentNullException("captchaCode");

            if (string.IsNullOrEmpty(captchaSid))
                throw new ArgumentNullException("captchaSid");

            return new LoginResults(html, catchaUrl, captchaCode, captchaSid, false);
        }

        public static LoginResults CreateInvalidUserNameOrPassowrd(string html)
        {
            return new LoginResults(html, string.Empty, string.Empty, string.Empty, false);
        }

        public static LoginResults CreateSucceeded(string html)
        {
            return new LoginResults(html, string.Empty, string.Empty, string.Empty, true);
        }

        public bool IsCaptchaRequired 
        {
            get { return !(Succeeded && string.IsNullOrEmpty(CaptchaUrl) && string.IsNullOrEmpty(CaptchaSid)); }
        }

        public string CaptchaCode { get; private set; }
        public string CaptchaSid { get; private set; }
        public string CaptchaUrl { get; private set; }
        public string Html { get; private set; }
        public bool Succeeded { get; private set; }
    }
}
